package com.Java.train.business.controller.daily;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import com.Java.train.business.entity.DTO.TrainDTO;
import com.Java.train.business.entity.Train;
import com.Java.train.business.service.TrainService;
import com.Java.train.business.service.daily.DailyTrainService;
import com.Java.train.common.exception.BusniessException;
import com.Java.train.common.exception.BusniessExceptionEnum;
import com.Java.train.common.response.CommonResp;
import com.Java.train.business.entity.DTO.DailyTrainDTO;
import com.Java.train.business.req.daily.DailyTrainQueryReq;
import com.Java.train.common.response.PageResp;
import com.Java.train.business.entity.DailyTrain;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import io.swagger.annotations.ApiOperation;
import jakarta.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;

import java.util.Date;
import java.util.List;
/**
* @author luomoxingchen
* @since 2024-09-24
*/
@RestController
@RequestMapping("/admin/daily-train")
public class DailyTrainController {
    private static final Logger LOG = LoggerFactory.getLogger(DailyTrainService.class);

    @Autowired
    private DailyTrainService dailyTrainService;
    @Resource
    private TrainService trainService;

    @GetMapping("/query-list")
    @ApiOperation("DailyTrain查询全部")
    public CommonResp< PageResp<DailyTrainDTO>> queryList(@Valid DailyTrainQueryReq dailyTrainQueryReq){
        PageResp<DailyTrainDTO> list = dailyTrainService.queryList(dailyTrainQueryReq);
        return new CommonResp<>(list);
    }

    @PostMapping("/save")
    @ApiOperation("DailyTrain修改")
    public CommonResp<Object> update(@Valid @RequestBody DailyTrain dailyTrain) {
        return dailyTrainService.modify(dailyTrain);
    }


    @DeleteMapping(value = "/delete/{ids}")
    @ApiOperation("DailyTrain删除(单个条目)")
    public CommonResp<Object> remove(@NotBlank(message = "{required}") @PathVariable String ids) {
        return dailyTrainService.remove(ids);
    }

    @GetMapping("/gen-daily/{date}")
    public CommonResp<Object> genDaily(@PathVariable(value = "date") @DateTimeFormat(pattern = "yyyy-MM-dd") Date date){
        dailyTrainService.genDaily(date);
        return new CommonResp<>(null);
    }

}
